home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 August: Tool Chest / Apple_Developer_Group_August_1996_Tool_Chest.iso / Sample Code / Snippets / QuickDraw / CopyMask / CopyMask.c next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  2.5 KB  |  93 lines  |  [TEXT/KAHL]

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                            */
  3. /*        CopyMask.                                                            */
  4. /*            by John Wang                                                    */
  5. /*                                                                            */
  6. /*        Description:    Shows how CopyMask can used to fade a screen to a    */
  7. /*            lighter color.                                                    */
  8. /*                                                                            */
  9. /*        Version:        1.0 Completed 12/2/91                                */
  10. /*                                                                            */
  11. /*--------------------------------------------------------------------------*/
  12.  
  13. #include    <QDOffscreen.h>
  14. main()
  15. {
  16.     WindowPtr        mainWinPtr;
  17.     OSErr            error;
  18.     SysEnvRec        theWorld;
  19.     GWorldPtr        myOffscreen1, myOffscreen2;
  20.     GDHandle        oldDevice;
  21.     CGrafPtr        oldPort;
  22.     Rect            windRect, offRect, myRect;
  23.     RGBColor        theColor;
  24.     int                theDepth, i;
  25.     
  26.     /* Make sure ColorQD exists. */
  27.     error = SysEnvirons(1, &theWorld);
  28.     if (theWorld.hasColorQD == false) {
  29.         SysBeep(50);
  30.         ExitToShell();
  31.     }
  32.     
  33.     /* Initialize all the needed managers. */
  34.     InitGraf(&qd.thePort);
  35.     InitFonts();
  36.     InitWindows();
  37.     InitMenus();
  38.     TEInit();
  39.     InitDialogs(nil);
  40.     InitCursor();
  41.  
  42.     /* Define output window. */
  43.     SetRect(&windRect, 100, 100, 400, 400);
  44.     SetRect(&offRect, 0, 0, 300, 300);
  45.     mainWinPtr = NewCWindow(nil, &windRect, "\pJohn", true, documentProc, (WindowPtr) -1, false, 0);
  46.     SetPort(mainWinPtr);
  47.     GetGWorld(&oldPort, &oldDevice);
  48.  
  49.     /* Create two offscreen GWorlds. */
  50.     if (NewGWorld(&myOffscreen1, 0, &offRect, nil, nil, 0))
  51.         Debugger();
  52.     if (NewGWorld(&myOffscreen2, 0, &offRect, nil, nil, 0))
  53.         Debugger();
  54.     
  55.     /* Now, draw ramp to first offscreen pixmap. */
  56.     SetGWorld(myOffscreen1, nil);
  57.     for (i=0; i<10; i++) {
  58.         theColor.red = theColor.green = theColor.blue = (i*28) << 8;
  59.         RGBForeColor(&theColor);
  60.         SetRect(&myRect, 0, i*30, 300, i*30+30);
  61.         PaintRect(&myRect);
  62.     }
  63.  
  64.     /* Now, draw mask to second offscreen pixmap. */
  65.     SetGWorld(myOffscreen2, nil);
  66.     SetRect(&myRect, 0, 0, 300, 300);
  67.     theColor.red = theColor.green = theColor.blue = (128) << 8;
  68.     RGBForeColor(&theColor);
  69.     PaintRect(&myRect);
  70.  
  71.     /*    Draw to the ramp to the window.    */
  72.     SetGWorld(oldPort, oldDevice);
  73.     CopyBits((BitMapPtr) *myOffscreen1->portPixMap, &(*mainWinPtr).portBits, &offRect,
  74.                 &offRect, 0, nil);
  75.  
  76.     /* Wait until user clicks button. */
  77.     do {
  78.     } while (!Button());
  79.     
  80.     /*    Now fade the window to white using CopyMask.  The destination must be erased
  81.         for CopyMask to work.    */
  82.     SetGWorld(oldPort, oldDevice);
  83.     EraseRect(&offRect);
  84.     CopyMask((BitMapPtr) *myOffscreen1->portPixMap, (BitMapPtr) *myOffscreen2->portPixMap,
  85.                 &(*mainWinPtr).portBits, &offRect, &offRect, &offRect);
  86.  
  87.     /* Wait until user clicks button. */
  88.     do {
  89.     } while (Button());
  90.     do {
  91.     } while (!Button());
  92. }
  93.